#include "MyGame.h"
#include "DxLib.h"

#include "../Common/Singleton.h"
#include "../Common/Assert.h"
#include "../Maths/Vector2.h"

#include "GameState.h"
#include "TestGameState.h"

MyGame::MyGame()
	: Game()
{
}

MyGame::~MyGame()
{
}

//float MyGame::GetAspectRatio() const
//{
//	return static_cast<float>( m_screenWidth ) / m_screenHeight;
//}

bool MyGame::Initialise()
{
	ChangeWindowMode( true );
	SetGraphMode( 800, 600, 32 );
	SetMainWindowText( "Rogue Like...ish?" );
	Game::Initialise();

	m_stateManager.AddState( GameStateType::GAME, new GameState( GameStateType::GAME ) );
	InputData::Data p1Input;
	p1Input.KEY_MOVE_DOWN	= KEY_INPUT_DOWN;
	p1Input.KEY_MOVE_UP		= KEY_INPUT_UP;
	p1Input.KEY_MOVE_LEFT	= KEY_INPUT_LEFT;
	p1Input.KEY_MOVE_RIGHT	= KEY_INPUT_RIGHT;
	p1Input.KEY_PAUSE		= KEY_INPUT_SPACE;

	InputData::Data p2Input;
	p2Input.KEY_MOVE_DOWN	= KEY_INPUT_S;
	p2Input.KEY_MOVE_UP		= KEY_INPUT_W;
	p2Input.KEY_MOVE_LEFT	= KEY_INPUT_A;
	p2Input.KEY_MOVE_RIGHT	= KEY_INPUT_D;
	p2Input.KEY_PAUSE		= KEY_INPUT_SPACE;

	m_inputData.SetData( p1Input, GameDefine::PLAYER_ONE );
	m_inputData.SetData( p2Input, GameDefine::PLAYER_TWO );

	return true;
}
 
void MyGame::Shutdown()
{
	m_stateManager.Clear();
	Game::Shutdown();
}

void MyGame::Update( const GameTime& gameTime )
{
	float delta = gameTime.GetElapsedTime();
	m_fps.Update( delta );
	m_camera.Update( delta );
	m_stateManager.Update( delta );

	if ( Input::GetInstance().IsKeyPressed( KEY_INPUT_ESCAPE ) )
	{
		this->Exit();
	}
}

void MyGame::Draw( const GameTime& gameTime )
{	
	m_stateManager.Draw( gameTime.GetElapsedTime() );
	DrawFormatString( 10, 10, GetColor( 255, 255, 255 ), "%.1f", m_fps.GetFps() );
	Game::Draw( gameTime );
}




